<?php

$page_title = "Shopping";
$rank_check = 1;
include "header.inc.php";

$findDiscount = fetch("SELECT * FROM discount_cards WHERE user = '$userid'");
$discountRate = "0%";
if ($findDiscount[id])
{
	$discount = $findDiscount[discount];
	$discountRate = $discount * 100;
	$discountRate = "$discountRate%";
}

$findShop = fetch("SELECT * FROM official_shops2 WHERE id = '$shop_id' AND game = '$game'");
if (!$findShop[id])
{
	die(header(error("shops.php?game=$game", "That shop does not exsist in this game!")));
}

print "$openHTML <br>";


if (file_exists("$rootPath/images/user_images/opg_$game/shopkeepers/keeper_$findShop[id].gif"))
{
	$showImage = "<img src=images/user_images/opg_$game/shopkeepers/keeper_$findShop[id].gif><br>";
}


print "<p align=center>$showImage<font size=-1><b>$findShop[shop_keeper]</b> says \"$findShop[shop_greeting]\"<Br><b><a href=discounts.php?game=$game>Current Discount</a>:</b> $discountRate</font></p>";

$findItems = mysql_query("SELECT * FROM shop_items2 WHERE sell_in = '$shop_id' AND cur_stock > '0' AND game = '$game'");
$numitems = mysql_num_rows($findItems);
if ($numitems <= 0) { print "<p align=center><i>There are currently no items in stock, please try back later today!</i></p>"; }
print "<table width=100%>";
while ($getItems = mysql_fetch_array($findItems))
{
	$getItem = fetch("SELECT * FROM items2 WHERE item_name = '$getItems[item_name]' AND game = '$game'");
	if ($findShop[haggle] == 1) { $haggle = "(<a href=haggle.php?game=$game&item_id=$getItems[id]&shop_id=$shop_id>HAGGLE</a>)"; }

	$y = $x % 5;
	if ($y == 0)
	{
		echo "<tr>";
	}
	if ($discount) { $getItems[sell_for] = $getItems[sell_for] - round($getItems[sell_for] * $discount); }

	echo "<td><p align=center>
	<a href='$base_url/buy_item.php?game=$game&item_id=$getItems[id]&shop_id=$shop_id' onClick=\"if ( !confirm ('Are you sure you want to purchase this $getItem[item_name] for $getItems[sell_for] $pointsVar?') ) { return false; }\">
	<img src=$base_url/images/user_images/opg_$game/items/item_$getItem[id].gif><br>
	$getItem[item_name]<br>
	$getItems[cur_stock] in Stock<br>
	$getItems[sell_for] $pointsVar
	</a>
	</p></td>";
	if ($y == 4)
	{
		echo "</tr>";
	}
	$x++;
}
print "</table>$closeHTML";

?>